package nl.ekok.Kentekencheck;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class KentekenDetails extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.result);
        
        // Show the details of the car that we retrieved from the sending activity
        showContent((Auto) getIntent().getParcelableExtra(Kentekencheck.AUTO_DETAILS));
        
    }
    
    private void showContent(Auto auto) {
    	
    	setText(R.id.hetkenteken, 0, auto.getKenteken());
    	setText(R.id.merkmodel, 0, auto.getMerk() + " " + auto.getModel());

    	if (auto.hasTechnicalInfo()) {
    		
	    	setText(R.id.motorCilinders, 0, auto.getMotorCilinders());
	    	setText(R.id.motorInhoud, 0, auto.getMotorInhoud());
	    	setText(R.id.motorVermogen, 0, auto.getMotorVermogen());
	    	setText(R.id.motorKoppel, 0, auto.getMotorKoppel());
	
	    	setText(R.id.gewicht, R.string.result_weight, auto.getGewicht());
	    	setText(R.id.topsnelheid, R.string.result_topspeed, auto.getTopsnelheid());
	    	setText(R.id.acceleratie, R.string.result_acceleration, auto.getAcceleratie());
	    	
    	} else {
    		
    		findViewById(R.id.motorCilinders).setVisibility(View.GONE);
    		findViewById(R.id.motorInhoud).setVisibility(View.GONE);
    		findViewById(R.id.motorVermogen).setVisibility(View.GONE);
    		findViewById(R.id.motorKoppel).setVisibility(View.GONE);
    		
	    	setText(R.id.gewicht, R.string.result_weight, auto.getGewicht());
    		findViewById(R.id.topsnelheid).setVisibility(View.INVISIBLE);
    		((TextView)findViewById(R.id.acceleratie)).setText(R.string.no_technical_info);
    	}
    }
    
    /**
     * Handy function to set the TextView's text, optionally with a prefix 
     * @param box The id of the TextView to set the text of
     * @param prefix An optional resource id to use for a prefix
     * @param value The actual value to set as a text
     */
    private void setText(int box, int prefix, String value) {
    	((TextView)findViewById(box)).setText(
    			(prefix > 0? getResources().getText(prefix) + ": ": "") + value);
    }
    
}
